package com.ruoyi.ihome.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.ihome.domain.Apartment;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ihome.domain.ApartmentFacility;
import com.ruoyi.ihome.service.IApartmentFacilityService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 公寓设施Controller
 * 
 * @author zy
 * @date 2024-08-13
 */
@RestController
@RequestMapping("/ihome/facility")
public class ApartmentFacilityController extends BaseController
{
    @Autowired
    private IApartmentFacilityService apartmentFacilityService;

    /**
     * 查询公寓设施列表
     */
    @PreAuthorize("@ss.hasPermi('ihome:facility:list')")
    @GetMapping("/list")
    public TableDataInfo list(ApartmentFacility apartmentFacility)
    {
        startPage();
        List<ApartmentFacility> list = apartmentFacilityService.selectApartmentFacilityList(apartmentFacility);
        return getDataTable(list);
    }

    /**
     * 根据设施 ID 列表查询公寓信息
     * @param facilityIds 设施 ID 列表
     * @return 与设施 ID 相关的公寓列表
     */

    /**
     * 导出公寓设施列表
     */
    @PreAuthorize("@ss.hasPermi('ihome:facility:export')")
    @Log(title = "公寓设施", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ApartmentFacility apartmentFacility)
    {
        List<ApartmentFacility> list = apartmentFacilityService.selectApartmentFacilityList(apartmentFacility);
        ExcelUtil<ApartmentFacility> util = new ExcelUtil<ApartmentFacility>(ApartmentFacility.class);
        util.exportExcel(response, list, "公寓设施数据");
    }

    /**
     * 获取公寓设施详细信息
     */
    @PreAuthorize("@ss.hasPermi('ihome:facility:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(apartmentFacilityService.selectApartmentFacilityById(id));
    }

    /**
     * 新增公寓设施
     */
    @PreAuthorize("@ss.hasPermi('ihome:facility:add')")
    @Log(title = "公寓设施", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ApartmentFacility apartmentFacility)
    {
        return toAjax(apartmentFacilityService.insertApartmentFacility(apartmentFacility));
    }

    /**
     * 修改公寓设施
     */
    @PreAuthorize("@ss.hasPermi('ihome:facility:edit')")
    @Log(title = "公寓设施", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ApartmentFacility apartmentFacility)
    {
        return toAjax(apartmentFacilityService.updateApartmentFacility(apartmentFacility));
    }

    /**
     * 删除公寓设施
     */
    @PreAuthorize("@ss.hasPermi('ihome:facility:remove')")
    @Log(title = "公寓设施", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(apartmentFacilityService.deleteApartmentFacilityByIds(ids));
    }
}
